package com.interview.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.interview.aspect.Editor;
import com.interview.aspect.User;
import com.interview.pojo.Product;
import com.interview.pojo.Result;
import com.interview.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping("/save")
    @Editor
    public Result<Boolean> save(@RequestBody Product product){
        return Result.ok(productService.save(product));
    }

    @DeleteMapping("/remove")
    public Result<Boolean> remove(Long id){
        return Result.ok(productService.removeById(id));
    }

    @PostMapping("/updateById")
    @Editor
    public Result<Boolean> updateById(@RequestBody Product product){
        return Result.ok(productService.updateById(product));
    }

    @GetMapping("/getOne")
    @User
    public Result<Product> updateById(Long id){
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        return Result.ok(productService.getOne(wrapper));
    }


}
